﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClearingRestartingAutomaton.Base
{
    /// <summary>
    /// The LearningStep structure describes one learning step.
    /// </summary>
    [Serializable]
    public struct LearningStep
    {
        #region Constructors

        /// <summary>
        /// Constructor of this structure.
        /// </summary>
        /// <param name="word">The input word which is the subject of the learning step.</param>
        /// <param name="startIndex">The starting position of the subword which is the subject of reduction.</param>
        /// <param name="length">The length of the subword which is the subject of reduction.</param>
        /// <param name="reduction">The resulting subword after the application of the learning step.</param>
        /// <param name="leftContext">The left context of the given input word.</param>
        /// <param name="rightContext">The right context of the given input word.</param>
        public LearningStep(
            string word,
            int startIndex,
            int length,
            string reduction,
            string leftContext,
            string rightContext)
        {
            this.word = leftContext + word + rightContext;
            this.startIndex = leftContext.Length + startIndex;
            this.length = length;
            this.reduction = reduction;
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// The whole left prefix including the left context that is to the left of 
        /// the subword representing the subject of reduction.
        /// </summary>
        public string LeftContext
        {
            get { return this.word.Substring(0, this.startIndex); }
        }

        /// <summary>
        /// The subword representing the subject of reduction.
        /// </summary>
        public string Center
        {
            get { return this.word.Substring(this.startIndex, this.length); }
        }

        /// <summary>
        /// The whole right suffix including the right context that is to the right of 
        /// the subword representing the subject of reduction.
        /// </summary>
        public string RightContext
        {
            get { return this.word.Substring(this.startIndex + this.length); }
        }

        /// <summary>
        /// The resulting subword after the application of the learning step.
        /// </summary>
        public string Reduction
        {
            get { return this.reduction; }
        }

        #endregion

        #region Private Data Members

        private string word;
        private int startIndex;
        private int length;
        private string reduction;

        #endregion
    }
}
